<!-- 订单列编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate ? '修改订单列' : '添加订单列'"
    :visible="visible"
    width="550px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label=" 用户ID:" prop="member_id">
        <el-input
          :maxlength="20"
          v-model="form.member_id"
          placeholder="请输入 用户ID"
          clearable
        />
      </el-form-item>

      <el-form-item label="用户账号:" prop="member_account">
        <el-input
          :maxlength="20"
          v-model="form.member_account"
          placeholder="请输入用户账号"
          clearable
        />
      </el-form-item>

      <el-form-item label="用户昵称:" prop="member_nickname">
        <el-input
          :maxlength="20"
          v-model="form.member_nickname"
          placeholder="请输入用户昵称"
          clearable
        />
      </el-form-item>

      <el-form-item label="游戏id:" prop="game_id">
        <el-input-number
          :min="0"
          v-model="form.game_id"
          placeholder="请输入游戏id"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="游戏appid:" prop="game_appid">
        <el-input
          :maxlength="20"
          v-model="form.game_appid"
          placeholder="请输入游戏appid"
          clearable
        />
      </el-form-item>

      <el-form-item label="游戏名称:" prop="game_name">
        <el-input
          :maxlength="20"
          v-model="form.game_name"
          placeholder="请输入游戏名称"
          clearable
        />
      </el-form-item>

      <el-form-item label="区服id:" prop="server_id">
        <el-input-number
          :min="0"
          v-model="form.server_id"
          placeholder="请输入区服id"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="区服名称:" prop="server_name">
        <el-input
          :maxlength="20"
          v-model="form.server_name"
          placeholder="请输入区服名称"
          clearable
        />
      </el-form-item>

      <el-form-item label="角色id:" prop="game_role_id">
        <el-input
          :maxlength="20"
          v-model="form.game_role_id"
          placeholder="请输入角色id"
          clearable
        />
      </el-form-item>

      <el-form-item label="角色名:" prop="game_role_name">
        <el-input
          :maxlength="20"
          v-model="form.game_role_name"
          placeholder="请输入角色名"
          clearable
        />
      </el-form-item>

      <el-form-item label="推广员id:" prop="promote_id">
        <el-input-number
          :min="0"
          v-model="form.promote_id"
          placeholder="请输入推广员id"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="推广员账号:" prop="promote_account">
        <el-input
          :maxlength="20"
          v-model="form.promote_account"
          placeholder="请输入推广员账号"
          clearable
        />
      </el-form-item>

      <el-form-item label="支付订单号:" prop="pay_order_number">
        <el-input
          :maxlength="20"
          v-model="form.pay_order_number"
          placeholder="请输入支付订单号"
          clearable
        />
      </el-form-item>

      <el-form-item label="道具名称:" prop="props_name">
        <el-input
          :maxlength="20"
          v-model="form.props_name"
          placeholder="请输入道具名称"
          clearable
        />
      </el-form-item>

      <el-form-item label="支付金额:" prop="pay_amount">
        <el-input
          :maxlength="20"
          v-model="form.pay_amount"
          placeholder="请输入支付金额"
          clearable
        />
      </el-form-item>

      <el-form-item label="支付时间:" prop="pay_time">
        <el-input
          :maxlength="20"
          v-model="form.pay_time"
          placeholder="请输入支付时间"
          clearable
        />
      </el-form-item>

      <el-form-item label="支付状态:" prop="pay_status">
        <el-input-number
          :min="0"
          v-model="form.pay_status"
          placeholder="请输入支付状态"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="游戏支付状态:" prop="pay_game_status">
        <el-input-number
          :min="0"
          v-model="form.pay_game_status"
          placeholder="请输入游戏支付状态"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="通知游戏方扩展(一般是游戏方透传):" prop="extend">
        <el-input
          :maxlength="20"
          v-model="form.extend"
          placeholder="请输入通知游戏方扩展(一般是游戏方透传)"
          clearable
        />
      </el-form-item>

      <el-form-item
        label="支付方式(1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 :"
        prop="pay_way"
      >
        <el-input-number
          :min="0"
          v-model="form.pay_way"
          placeholder="请输入支付方式(1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 "
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="支付IP:" prop="spend_ip">
        <el-input
          :maxlength="20"
          v-model="form.spend_ip"
          placeholder="请输入支付IP"
          clearable
        />
      </el-form-item>

      <el-form-item label="区别sdk版本1安卓 2苹果 :" prop="sdk_version">
        <el-input-number
          :min="0"
          v-model="form.sdk_version"
          placeholder="请输入区别sdk版本1安卓 2苹果 "
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="原价:" prop="cost">
        <el-input
          :maxlength="20"
          v-model="form.cost"
          placeholder="请输入原价"
          clearable
        />
      </el-form-item>

      <el-form-item label="苹果服务器返回json:" prop="receipt">
        <el-input
          :maxlength="20"
          v-model="form.receipt"
          placeholder="请输入苹果服务器返回json"
          clearable
        />
      </el-form-item>

      <el-form-item label="自动补单次数:" prop="auto_compensation">
        <el-input-number
          :min="0"
          v-model="form.auto_compensation"
          placeholder="请输入自动补单次数"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="设备号 ios存储idfa 安卓存储imei:" prop="device">
        <el-input
          :maxlength="20"
          v-model="form.device"
          placeholder="请输入设备号 ios存储idfa 安卓存储imei"
          clearable
        />
      </el-form-item>

      <el-form-item label="cp订单号:" prop="jh_order_number">
        <el-input
          :maxlength="20"
          v-model="form.jh_order_number"
          placeholder="请输入cp订单号"
          clearable
        />
      </el-form-item>

      <el-form-item label="用户注册时间:" prop="register_time">
        <el-input
          :maxlength="20"
          v-model="form.register_time"
          placeholder="请输入用户注册时间"
          clearable
        />
      </el-form-item>

      <el-form-item label="是否沙盒 0否 1是:" prop="is_sandbox">
        <el-input-number
          :min="0"
          v-model="form.is_sandbox"
          placeholder="请输入是否沙盒 0否 1是"
          controls-position="right"
          class="ele-fluid ele-text-left"
        />
      </el-form-item>

      <el-form-item label="收款账号:" prop="collect_account">
        <el-input
          :maxlength="20"
          v-model="form.collect_account"
          placeholder="请输入收款账号"
          clearable
        />
      </el-form-item>

      <el-form-item label="商品描述:" prop="body">
        <el-input
          :maxlength="20"
          v-model="form.body"
          placeholder="请输入商品描述"
          clearable
        />
      </el-form-item>

      <el-form-item label="商品名称:" prop="title">
        <el-input
          :maxlength="20"
          v-model="form.title"
          placeholder="请输入商品名称"
          clearable
        />
      </el-form-item>

      <el-form-item label="实收状态:" prop="paid_status">
        <el-select
          clearable
          class="ele-block"
          v-model="form.paid_status"
          placeholder="请选择实收状态"
        >
          <el-option label="1=未确认2=正常3=异常" :value="123" />
        </el-select>
      </el-form-item>

      <el-form-item label="下单时间:" prop="add_time">
        <el-input
          :maxlength="20"
          v-model="form.add_time"
          placeholder="请输入下单时间"
          clearable
        />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" @click="save" :loading="loading"
        >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
// import uploadImage from '@/components/uploadImage'

export default {
  name: 'OrderEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  // components: { uploadImage },
  data() {
    return {
      // 表单数据
      form: Object.assign({ status: 1 }, this.data),
      // 表单验证规则
      rules: {
        member_id: [
          { required: true, message: '请输入 用户ID', trigger: 'blur' }
        ],
        member_account: [
          { required: true, message: '请输入用户账号', trigger: 'blur' }
        ],
        member_nickname: [
          { required: true, message: '请输入用户昵称', trigger: 'blur' }
        ],
        game_id: [{ required: true, message: '请输入游戏id', trigger: 'blur' }],
        game_appid: [
          { required: true, message: '请输入游戏appid', trigger: 'blur' }
        ],
        game_name: [
          { required: true, message: '请输入游戏名称', trigger: 'blur' }
        ],
        server_id: [
          { required: true, message: '请输入区服id', trigger: 'blur' }
        ],
        server_name: [
          { required: true, message: '请输入区服名称', trigger: 'blur' }
        ],
        game_role_id: [
          { required: true, message: '请输入角色id', trigger: 'blur' }
        ],
        game_role_name: [
          { required: true, message: '请输入角色名', trigger: 'blur' }
        ],
        promote_id: [
          { required: true, message: '请输入推广员id', trigger: 'blur' }
        ],
        promote_account: [
          { required: true, message: '请输入推广员账号', trigger: 'blur' }
        ],
        pay_order_number: [
          { required: true, message: '请输入支付订单号', trigger: 'blur' }
        ],
        props_name: [
          { required: true, message: '请输入道具名称', trigger: 'blur' }
        ],
        pay_amount: [
          { required: true, message: '请输入支付金额', trigger: 'blur' }
        ],
        pay_time: [
          { required: true, message: '请输入支付时间', trigger: 'blur' }
        ],
        pay_status: [
          { required: true, message: '请输入支付状态', trigger: 'blur' }
        ],
        pay_game_status: [
          { required: true, message: '请输入游戏支付状态', trigger: 'blur' }
        ],
        extend: [
          {
            required: true,
            message: '请输入通知游戏方扩展(一般是游戏方透传)',
            trigger: 'blur'
          }
        ],
        pay_way: [
          {
            required: true,
            message:
              '请输入支付方式(1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 ',
            trigger: 'blur'
          }
        ],
        spend_ip: [
          { required: true, message: '请输入支付IP', trigger: 'blur' }
        ],
        sdk_version: [
          {
            required: true,
            message: '请输入区别sdk版本1安卓 2苹果 ',
            trigger: 'blur'
          }
        ],
        cost: [{ required: true, message: '请输入原价', trigger: 'blur' }],
        receipt: [
          {
            required: true,
            message: '请输入苹果服务器返回json',
            trigger: 'blur'
          }
        ],
        auto_compensation: [
          { required: true, message: '请输入自动补单次数', trigger: 'blur' }
        ],
        device: [
          {
            required: true,
            message: '请输入设备号 ios存储idfa 安卓存储imei',
            trigger: 'blur'
          }
        ],
        jh_order_number: [
          { required: true, message: '请输入cp订单号', trigger: 'blur' }
        ],
        register_time: [
          { required: true, message: '请输入用户注册时间', trigger: 'blur' }
        ],
        is_sandbox: [
          { required: true, message: '请输入是否沙盒 0否 1是', trigger: 'blur' }
        ],
        collect_account: [
          { required: true, message: '请输入收款账号', trigger: 'blur' }
        ],
        body: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
        title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],

        paid_status: [
          { required: true, message: '请选择实收状态', trigger: 'blur' }
        ],
        add_time: [
          { required: true, message: '请输入下单时间', trigger: 'blur' }
        ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    }
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data)
        this.isUpdate = true
      } else {
        this.form = {}
        this.isUpdate = false
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.$http
            .post('/order/edit', this.form)
            .then((res) => {
              this.loading = false
              if (res.data.code === 0) {
                this.$message.success(res.data.msg)
                if (!this.isUpdate) {
                  this.form = {}
                }
                this.updateVisible(false)
                this.$emit('done')
              } else {
                this.$message.error(res.data.msg)
              }
            })
            .catch((e) => {
              this.loading = false
              this.$message.error(e.message)
            })
        } else {
          return false
        }
      })
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value)
    }
  }
}
</script>

<style scoped>
</style>
